I tried Reducing Lambda cost by using lambda power tuning

I tried Reducing Lambda cost by using lambda power tuning

Clock Icon2022.10.17

この記事は公開されてから1年以上経過しています。情報が古い可能性がありますので、ご注意ください。

How Lambda pricing works

https://aws.amazon.com/lambda/pricing/

  1. It charges us based on the amount of memory allocated to the function

we can save money by allocating appropriate memory

  1. how long the function runs by the millisecond

  2. also charges the fixed price of 0.20$ per million requests (or invocation)

Extra cost: Data transfer cost

Lambda@Edge Pricing

When to optimize Lambda functions for cost?

  1. we should always optimize lambda functions that use provision concurrency

1 provisioned concurrency with 128mb memory = 1.40$ per month

1 provisioned concurrency with 10GB memory = 111.16$ per month

  1. a function that invokes millions of times with a long execution time

we can save money by allocating more memory if a task needs more CPU cycle

task can be cheaper if choosing more memory for a short amount of time as compared to running for a longer amount of time with less memory

Lambda power tuning- help to find the best memory Setting for your app

this will help you to choose the right size of memory based on performance, cost or a combination of both

I tried

I already created a temp lambda function for testing

https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:451282441545:applications~aws-lambda-power-tuning

  • open the above link and click on deploy >

check on I acknowledge that this app creates custom IAM roles. > deploy

  • after Deployment is successfully completed -> State Function State Machine -> click on power tuning State machine

  •  click on Execute

paste the json payload with your lambda function ARN and strategy


{
"lambdaARN": "your-lambda-function-arn",
"powerValues": [128, 256, 512, 1024, 2048, 3008],
"num": 10,
"payload": "{}",
"parallelInvocation": true,
"strategy": "cost"
}

  • after Execution you can check the output and recommended memory Setting for your strategy

 

  • we can also see the visualization by opening link available in output

 

 

reason for not always using lambda-power-tuning :
  • Capture and maintain payload for Each function
  • plan and execute function for each function
  • cost of running power tuning State machine
  • Repeat every time the function Changes
  • Require time

 

Picking the right functions to power tuning

We should sort all our function and choose the function which are costing more and power tune them

Other ways to save money

Using ARM architecture

graviton is 25% Cheaper than x86

can be considered if your application is not required intensive io

Using provisioned concurrency

provisioned concurrency is 70 % cheaper as compare to On Demand

 

References:

https://serverlessrepo.aws.amazon.com/applications/arn:aws:serverlessrepo:us-east-1:451282441545:applications~aws-lambda-power-tuning

Conclusion:

Hope you can save few bugs using above Information

Thank you,

Share this article

facebook logohatena logotwitter logo

© Classmethod, Inc. All rights reserved.